package com.yanze.schoolinformation.adapter.rv;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.ViewGroup;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewAdapter;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewHolder;
import com.yanze.schoolinformation.databinding.ItemWanAndroidBinding;
import com.yanze.schoolinformation.model.bean.WanAndroidListBean;
import com.yanze.schoolinformation.view.webview.WebViewActivity;

/**
 * Created by MrZheng on 2018/4/28.
 */

public class WanAndroidAdapter extends BaseRecyclerViewAdapter<WanAndroidListBean.DataBean.DatasBean> {

    private Context activity;

    public WanAndroidAdapter(Context activity) {
        this.activity = activity;
    }

    @NonNull
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(parent, R.layout.item_wan_android);
    }

    private class ViewHolder extends BaseRecyclerViewHolder<WanAndroidListBean.DataBean.DatasBean,ItemWanAndroidBinding> {

        public ViewHolder(ViewGroup viewGroup, int layoutId) {
            super(viewGroup, layoutId);
        }

        @Override
        public void onBindViewHolder(WanAndroidListBean.DataBean.DatasBean datasBean, int position) {
            if (datasBean != null) {
                binding.setBean(datasBean);
                binding.setAdapter(WanAndroidAdapter.this);
                binding.executePendingBindings();
            }
        }
    }

    public void openDetail(WanAndroidListBean.DataBean.DatasBean bean) {
        WebViewActivity.loadUrl(activity, bean.getLink(), bean.getTitle());
    }
}
